package model;

import android.util.Log;

import org.json.JSONObject;

import java.io.IOException;
import java.util.List;

import base.BaseModel;
import base.BaseObserver;
import base.ResultCallBack;
import bean.LunTanSchoolNewsBean;
import bean.ResultBean;
import io.reactivex.Observable;
import jiyun.com.yiyanmeng.http.HttpManager;
import jiyun.com.yiyanmeng.http.MySerivce;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.ResponseBody;
import utils.RxUtil;

/**
 * Created by zhang'lin'lin on 2019/11/6.
 */

public class LunTanNewsModel extends BaseModel {

    public void getData(int id, int page, final ResultCallBack <List <LunTanSchoolNewsBean>> resultCallBack) {
        MySerivce serivce = HttpManager.getInstance().getSerivce();
        Observable <ResultBean <List <LunTanSchoolNewsBean>>> newsbean = serivce.newsbean(id, page);
        newsbean.compose(RxUtil.<ResultBean<List<LunTanSchoolNewsBean>>>changeThread())
                .compose(RxUtil.<List<LunTanSchoolNewsBean>>changeResult())
                .subscribe(new BaseObserver <List <LunTanSchoolNewsBean>>() {
                    @Override
                    public void onSuccess(List <LunTanSchoolNewsBean> lunTanSchoolNewsBeans) {
                        Log.i("123", "onSuccess: "+lunTanSchoolNewsBeans.toString());
                        resultCallBack.onSuccess(lunTanSchoolNewsBeans);
                    }

                    @Override
                    public void onFail(String error) {
                        resultCallBack.onFail(error);
                    }
                });
    }

}
